
<%@page import="acceso.beans.PaginaBean"%>
<%@page import="wf.dto.ContenedorDto"%>
<%
    response.setHeader("Cache-Control","no-cache");
    response.setHeader("Cache-Control","no-store");
    response.setHeader("Cache-Control","must-revalidate");
    response.setHeader("Pragma","no-cache");
    response.setDateHeader ("Expires", (new java.util.Date()).getTime());
    
    String es = request.getHeader("user-agent");
    boolean Apple = false;
    if((es.indexOf("iPad")>-1 | es.indexOf("iPhone")>-1 | es.indexOf("Safari")>-1) & (es.indexOf("Chrome")==-1) ) {
        Apple=true;
    }
%>
<%@page contentType="text/html"%>
<%@page pageEncoding="ISO-8859-1"%>
<%@page import="wf.dto.PaginaDto"%>
<%@page import="java.util.List" %>
<%@page import="java.util.Iterator" %>
<%@page import="java.util.Date" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

    <c:catch var="mela">
    <jsp:setProperty name="paginaBean" property="p_co_pagina" value="${p.id.co_pagina}"/>
    <jsp:setProperty name="paginaBean" property="p_id_frawor" value="${param.id_frawor}"/>
    <jsp:setProperty name="paginaBean" property="p_co_conten" value="${contenedor.co_conten}"/>
    <jsp:setProperty name="paginaBean" property="ip" value="<%=request.getRemoteHost() %>"/>
    <jsp:setProperty name="paginaBean" property="auxiliar" value="do"/>
    
    
    <jsp:useBean id="georefBean" scope="request" class="acceso.beans.GeorefBean"></jsp:useBean>

    <c:if test="${paginaBean.pintado}">

    <!--Load the AJAX API-->
    

    <script type="text/javascript">
/*
   
    }*/
        //**********************************************
        
        google.load('visualization', '1.0', {'packages':['corechart']});
        google.setOnLoadCallback(drawChart);
        
        function drawChart() {
            var opciones = {"titulo":"${p.no_pagtit}","tipo":"${p.no_pagtit}"};
            
            var tit = [];
            <c:forEach var="titulo" items="${paginaBean.ltit }">
                tit[tit.length] = '${titulo.no_pagtit}';
            </c:forEach>
            //hallar numero de columnas
            var num_col = 0;
            var num_fila = 0;
            var multi_array = new Array();
            multi_array[num_col] = new Array();
            <c:forEach var="registro" items="${paginaBean.lreg}" >
                <c:if test="${registro.ti_estreg != 'O'}">
                    multi_array[num_col][num_fila] = '${registro.no_pagreg}';
                    //alert("--"+multi_array[num_col][num_fila]);
                    num_fila++;
                </c:if>
            </c:forEach>
            num_col++;
            num_fila=0;
            
            var filas = 0;
            var prom_col = [];
            prom_col[0]="promedio";
            <c:forEach begin="1" end="${paginaBean.vueltas}" var="r">
                <jsp:setProperty name="paginaBean" property="fin" value="${paginaBean.ini+paginaBean.registros}"/>
                multi_array[num_col] = new Array();
                var prom_fil = 0;
                <c:forEach var="vregistro" items="${paginaBean.lval}" begin="${paginaBean.ini}" end="${paginaBean.fin-1}" varStatus="status">
                    <c:if test="${(not empty vregistro.ti_pagreg)}">
                        <c:if test="${vregistro.ti_estreg != 'O'}">
                            if(num_fila == 0){
                                multi_array[num_col][num_fila] = '${vregistro.va_pagreg}';
                            }else{
                                prom_fil = prom_fil+parseInt('${vregistro.va_pagreg}');
                                multi_array[num_col][num_fila] = parseInt('${vregistro.va_pagreg}');
                            }
                            //alert(multi_array[num_col][num_fila]);
                            num_fila++;
                        </c:if>
                    </c:if>
                </c:forEach>
                prom_col[prom_col.length] = prom_fil/(num_fila-1);
                //alert(num_fila);
                filas = num_fila;
                num_fila = 0;
                num_col++;
                <jsp:setProperty name="paginaBean" property="ini" value="${paginaBean.fin}"/>
            </c:forEach>
            
            
            
            var width = 550;
            var height = 300;
            if(${t.nu_colspa} == ${p.nu_colspa}){
                width = width*${t.nu_colspa};
                height = height*(1+(0.25*${t.nu_colspa}));
                
            }


                    
            var options = {'title':opciones.tipo,
                        'width':width,
                        'height':height,
                        'fontName':'Tahoma',
                        'vAxis': {title: tit[1],  titleTextStyle: {color: 'black', fontSize: 15}},
                        'hAxis': {title: tit[0],  titleTextStyle: {color: 'black', fontSize: 15}},
                        'font-weight':'bold'
                        };
            var chart;
            if(opciones.tipo=="BarChart"){
                var data = google.visualization.arrayToDataTable(multi_array);
                chart = new google.visualization.BarChart(document.getElementById('chart_div${p.id.co_pagina}'));
                chart.draw(data, options);
            }else if(opciones.tipo=="ColumnChart"){
                var data = google.visualization.arrayToDataTable(multi_array);
                chart = new google.visualization.ColumnChart(document.getElementById('chart_div${p.id.co_pagina}'));
                chart.draw(data, options);
            }else if(opciones.tipo=="PieChart"){
                var data = google.visualization.arrayToDataTable(multi_array);
                chart = new google.visualization.PieChart(document.getElementById('chart_div${p.id.co_pagina}'));
                chart.draw(data, options);
            }else if(opciones.tipo=="ComboChart"){
                //alert("comparacion "+multi_array.length+","+prom_col.length);
                for(var i=0;i<multi_array.length;i++){
                    var arr = multi_array[i];
                    //alert("arr "+arr.length);
                    multi_array[i][arr.length] = prom_col[i];
                }
                options.seriesType = "bars";
                //alert(">>>"+options);
                options.series = {<%=2 %>: {type: "line"}}
                //options.series = {''+filas+'': {type: "line"}}
                //options.series = eval('{'+(filas-1)+':{type: "line"}}');
                //options.series = eval('{2 : { type: \"line\"} }');
                //options.series =JSON.parse('{ 2: {type : \"line\"} }');
                //options.series[filas]= {type: "line"};
                
    
                
                var data = google.visualization.arrayToDataTable(multi_array);
                chart = new google.visualization.ComboChart(document.getElementById('chart_div${p.id.co_pagina}'));
                chart.draw(data, options);
                /*
                for(var i=0;i<=filas;i++){
                    if(i==filas){
                        chart.options.series.push({type: "line"});
                    }else{
                        chart.options.series.push({type: "bars"});
                    }
                }*/
            }else{
                var m = "Tipo de grafico no definido";
                $D.g_ID("modalDialogPageBackground").style.display="block";
                $D.g_ID("block_pane2").style.display="block";
                $D.g_ID("block_pane2").style.display="none";
                mensaje(null, m, null, null, 3)
            }

        } 
        
        
      
    </script>


      
    <table id="tabla${p.id.co_pagina}" cellpadding='0' cellspacing='1' border="1"  align="center" width="100%" nowrap class="tdonline fixedheader" >
        <thead id="tablahead${p.id.co_pagina}" class="iqarothead">
            <tr>
                <c:if test="${paginaBean.botones_e}">
                    <th align="left" colspan="${paginaBean.registros+1}" class="pagina" style="padding: 0px;height: 17px;background: white;border-bottom: 1px #DCDCDC solid; border-left: 1px white solid; border-right: 1px white solid; border-top: 1px white solid;">
                        <div style="display: table;width:100%" class="tdonline3" >
                            <div style="display: table-row;">
                                <div align="left" width="80%" style="display: table-cell;width: 80%;" class="texto13b">
                                    <label>${p.no_pagtit}</label>
                                </div>
                                <div class="titulo11" align="right" width="20%" onmouseover="style.color='#073362'; style.cursor='hand';style.display='table-cell';this.getElementsByTagName('a')[0].style.display='inline-table'" onmouseout="style.color='white';this.getElementsByTagName('a')[0].style.display='none';" style="font-weight: normal;">
                                    <label>${contenedor.co_conten} / ${p.id.co_pagina}</label>
                                    <a id="pag_form_th_div_div_d2_a" href="../workflow2/contenedorxls_bk.jsp?id_frawor=${param.id_frawor}&co_pagina=${p.id.co_pagina}" class="enlaceLista" style="display: none; vertical-align: bottom;">
                                        <img border=0 src="../img/excel-disabled.jpeg" align="center" style="cursor: pointer; width: 14px;height: 14px;margin: 0px;" alt="Exportar a excel" title="Exportar a excel" />
                                    </a>
                                </div>
                            </div>
                        </div>
                    </th>
                </c:if>
                <c:if test="${!paginaBean.botones_e}">
                    <%--th align="left" colspan="${paginaBean.registros}" class="pagina" style="border-top-color: white; border-left-color: white; border-right-color: white; border-bottom-color: #E7E8E6;padding: 0px;border-width: 1px;height: 17px;background: white;border-left: 1px white solid;"--%>
                    <th align="left" colspan="${paginaBean.registros}" class="pagina" style="padding: 0px;height: 17px;background: white;border-bottom: 1px #DCDCDC solid; border-left: 1px white solid; border-right: 1px white solid; border-top: 1px white solid;">
                        <div style="display: table;width:100%" class="tdonline3" >
                            <div style="display: table-row;">
                                <div align="left" width="80%" style="display: table-cell;width: 80%;" class="texto13b">
                                    <label>${p.no_pagtit}</label>
                                </div>
                                <div class="titulo11" align="right" width="20%" onmouseover="style.color='#073362'; style.cursor='hand';style.display='table-cell';this.getElementsByTagName('a')[0].style.display='inline-table'" onmouseout="style.color='white';this.getElementsByTagName('a')[0].style.display='none';" style="font-weight: normal;">
                                    <label>${contenedor.co_conten} / ${p.id.co_pagina}</label>
                                    <a id="pag_form_th_div_div_d2_a" href="../workflow2/contenedorxls_bk.jsp?id_frawor=${param.id_frawor}&co_pagina=${p.id.co_pagina}" class="enlaceLista" style="display: none; vertical-align: bottom;">
                                        <img border=0 src="../img/excel-disabled.jpeg" align="center" style="cursor: pointer; width: 14px;height: 14px;margin: 0px;" alt="Exportar a excel" title="Exportar a excel" />
                                    </a>
                                </div>
                            </div>
                        </div>
                    </th>
                </c:if>
            </tr>

        </thead>
        <tbody>
            <tr>
                <td>
                    <div id="chart_div${p.id.co_pagina}"></div>
                </td>
            </tr>
        </tbody>
    </table>
      <!--Div that will hold the pie chart-->
   </c:if>
    <c:if test="${!paginaBean.pintado}">
        <input type="hidden" id="tabla${p.id.co_pagina}" />
        <script>
            var v = $D.g_ID('tabla'+${p.id.co_pagina});
            v = v.getParent().getParent();//.getParent();
            if(v.tagName == 'TD'){
                var v1 = v.getParent();
                if(v1.tagName == 'TR'){
                    if(v1.cells.length == 1){
                        v1.style.display = "none";
                    }else if(v1.cells.length > 1){
                        var actual = true;
                        for(var i = 0; i< v1.cells.length ;i++){
                            var y = v1.cells[i].getElementsByTagName("DIV")[0].getElementsByTagName("TABLE").length;
                            //alert("y=["+y+"]");
                            if(y == 0){
                                //es un oculto
                                actual = actual & true;
                                v1.cells[i].style.display = "none";
                            }else{
                                actual = actual & false;
                                //es una tabla
                            }
                        }
                        if(actual == true) v1.style.display = "none";
                        else v1.style.display = "table-row";
                        //v.style.display = "none";
                    }
                }
            }
        </script>
    </c:if>
    <jsp:setProperty name="paginaBean" property="reset" value="reset"/><%--Metodo para resetear las variables--%>
</c:catch>
<c:if test="${mela !=null}">
    <c:set scope="session" var="Error" value="${paginaBean.exception}"/>
    <script>
        succes_error();
    </script>
</c:if>   